home *** CD-ROM | disk | FTP | other *** search
- unit ChildMainFormUnit;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Edit1: TEdit;
- Button1: TButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- PipeWrite: THandle;
- end;
-
- {$ifdef Ver90}
- //This exception class did not exist in Delphi 2
- EWin32Error = class(Exception);
- {$endif}
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {$ifdef Ver90}
- //This function class did not exist in Delphi 2
- function Win32Check(RetVal: Bool): Bool;
- var
- LastError: DWord;
- begin
- Result := RetVal;
- if not RetVal then
- begin
- LastError := GetLastError;
- if LastError <> Error_Success then
- raise EWin32Error.CreateFmt( 'Win32 Error. Code: %d.'#10'%s',
- [LastError, SysErrorMessage(LastError)])
- else
- raise EWin32Error.Create('A Win32 API function failed')
- end;
- end;
- {$endif}
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- PipeWrite := GetStdHandle(Std_Output_Handle)
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- CloseHandle(PipeWrite);
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- BytesWritten: DWord;
- Msg: String;
- begin
- Msg := Edit1.Text + #13#10;
- Win32Check(WriteFile(PipeWrite, Msg[1], Length(Msg),
- BytesWritten, nil));
- end;
-
- end.
-